package com.zsj.hello.Second;

import com.rabbitmq.client.Channel;
import com.zsj.hello.util.RabbimqFactoryUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author https://gitee.com/zhengshengjun
 * @date 2023/8/29.
 * <p>
 * 消息的生产者
 */
public class Producer {

    public static final String QUEUE_NAME = "hello";

    public static void main(String[] args) {
        int i = 1;
        try {

            Channel rabbitMQChannel = RabbimqFactoryUtil.getRabbitMQChannel();
//            rabbitMQChannel.queueDeclare(QUEUE_NAME, false, false, false, null);
            //发送消息
            while (true) {
                String message = "it is test message";
                rabbitMQChannel.basicPublish("", QUEUE_NAME, null, message.getBytes());
                System.out.println("发送" + ++i + "条消息");
            }
        } catch (IOException e) {
        } catch (TimeoutException e) {
            throw new RuntimeException(e);
        }


    }
}
